
/** $Id: Amf3Decoder.java 60 2009-06-15 08:47:09Z salbanese0080@gmail.com $ */

package org.aquiferserver.server.net;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.handler.codec.string.StringDecoder;

/**
 * @author Seth Albanese
 *
 */
@ChannelPipelineCoverage("all")
public class Amf3Decoder extends StringDecoder {

	protected final Log logger = LogFactory.getLog( org.aquiferserver.server.net.Amf3Decoder.class );
	
	/* (non-Javadoc)
	 * @see org.jboss.netty.handler.codec.oneone.OneToOneDecoder#decode(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.Channel, java.lang.Object)
	 */
	@Override
	protected Object decode(ChannelHandlerContext ctx, Channel c, Object msg ) throws Exception 
	{		
		Object src = super.decode( ctx, c, msg);
		if( !( src instanceof String ) )
		{
			return src;
		}
		
		Amf3Codec codec = ( Amf3Codec ) CodecFactory.getCodec();
		Object dec = codec.decode( ( String ) src );
		logger.debug( "Decoded instance of " + dec.getClass().getCanonicalName() );
		return dec;
	}

}
